package com.liu.service.impl;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.liu.config.RedisConfig;
import com.liu.dao.ViewDao;
import com.liu.service.intf.ViewService;
import com.liu.utils.JedisUtils;
import com.liu.vo.R;
import entity.View;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ViewServiceImpl implements ViewService {
    @Autowired
    private ViewDao dao;
//    private Logger logger = LoggerFactory.getLogger(ViewServiceImpl.class);

    public R queryAllView(){

        List<entity.View> views;
        if (JedisUtils.getStr(RedisConfig.LUOYANG_VIEW)!=null){
            views = JSON.parseArray(JedisUtils.getStr(RedisConfig.LUOYANG_VIEW), entity.View.class);
            return R.ok(views);
        }
        else {
            QueryWrapper<View> queryWrapper = new QueryWrapper<>();
            queryWrapper.orderByDesc("id");
            views = dao.selectList(queryWrapper);
            JedisUtils.setSet(RedisConfig.LUOYANG_VIEW,JSON.toJSONString(views));
            return R.ok(views);
        }
    }
}
